package com.cc.infrastructure.special.impl;

import com.cc.infrastructure.special.dto.AmountDo;
import com.cc.infrastructure.special.impl.AmountDao;
import com.sccin.components.jpa.entiy.ParamConditionBO;
import com.sccin.components.jpa.entiy.type.ConditionEnum;
import com.sccin.components.query.AutoPageJpa;
import com.sccin.components.utils.auto.AutoUtil;
import com.sccin.components.utils.auto.parseParamCondition.RequirParametersAndConditions;
import org.springframework.data.domain.Page;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

public class Amountimpl implements AmountDao {
  @PersistenceContext
  private EntityManager entityManager;

  @Override
  public Page<AmountDo> query(String name, int pageNum, int pageSize) {
    AutoPageJpa<AmountDo> autoPageJpa = new AutoPageJpa<>(AmountDo.class);
    StringBuilder select = new StringBuilder("SELECT id,supply_id,money_type,amount");
    StringBuilder from = new StringBuilder("FROM amount");

    RequirParametersAndConditions<ParamConditionBO, Object> where = RequirParametersAndConditions.getInstance();
    where.initParamAndCondition("xxx", Condition.eq, 1).initParamAndCondition("xxx2", Condition.like, 2).initParamAndCondition("xxx3", Condition.contain, 3);
    return autoPageJpa.autopage(select, null, from, where, null, AutoUtil.initPageable(pageNum, pageSize), entityManager);
  }
}